import {defineStore} from 'pinia';

export const useMessage = defineStore('messageService', {
  state() {
    return {
      msg: {
        state: 0,
        type: 'info',
        duration: 3000,
        msg: '-'
      }
    }
  },
  actions: {
    info(msg, dur = 3000) {
      let {state} = this.msg;
      this.msg.state = state === 0 ? 1 : 0;
      this.msg.msg = msg;
      this.msg.duration = dur
      this.msg.type = 'info';
    },
    success(msg, dur = 3000) {
      let {state} = this.msg;
      this.msg.state = state === 0 ? 1 : 0;
      this.msg.msg = msg;
      this.msg.duration = dur
      this.msg.type = 'success';
    },
    error(msg, dur = 3000) {
      let {state} = this.msg;
      this.msg.state = state === 0 ? 1 : 0;
      this.msg.msg = msg;
      this.msg.duration = dur
      this.msg.type = 'error';
    }
  }
})
